package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.constant.SysConstant;
import com.jianyun.jyzs.dao.ItemModel;
import com.jianyun.jyzs.utils.RceLog;

import java.util.List;



public class OATopAdapter extends BaseAdapter {
    private Context context;
    List<ItemModel> list;//存放图标及消息提醒
    private int count = 0;

    public OATopAdapter(Context context, List<ItemModel> list) {
        this.context = context;
        this.list = list;
    }


    public void setList(List<ItemModel> list) {
        this.list = list;
        notifyDataSetChanged();
        RceLog.d("lml", "notifyDataSetChanged");
    }

    public void setSpCunt(int count) {
        this.count = count;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MsgViewHolder mHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_app_top_view, null);
            mHolder = new MsgViewHolder();
            mHolder.iv_msgImg = (ImageView) convertView.findViewById(R.id.ItemImage);
            mHolder.tv_unRead = (TextView) convertView.findViewById(R.id.tv_unRead);
            mHolder.tv_text = (TextView) convertView.findViewById(R.id.ItemText);
            convertView.setTag(mHolder);
        } else {
            mHolder = (MsgViewHolder) convertView.getTag();
        }

        // 给mHolder类中的对象赋值.
        ItemModel vo = list.get(position);
       // mHolder.iv_msgImg.setImageResource(vo.getImgRes());
        mHolder.iv_msgImg.setImageResource(SysConstant.img_list[position]);
        if (vo.getTitle() != null && vo.getTitle().equals("签到")) {
            mHolder.tv_text.setTextColor(context.getResources().getColor(R.color.appTopFont));
        } else {
            mHolder.tv_text.setTextColor(context.getResources().getColor(R.color.white));
        }
        mHolder.tv_text.setText(vo.getTitle());

//		if(vo.isShow){
//			mHolder.tv_unRead.setVisibility(View.VISIBLE);
//			mHolder.tv_unRead.setText(vo.count+"");
//		}else{
//			mHolder.tv_unRead.setVisibility(View.GONE);
//		}

//		if (position!=1&&!vo.isUnRead()){
//			mHolder.tv_unRead.setVisibility(View.GONE);
//		}else {
//			mHolder.tv_unRead.setVisibility(View.VISIBLE);
//		}
        if (position == 1 && count != 0) {

            mHolder.tv_unRead.setVisibility(View.VISIBLE);
            mHolder.tv_unRead.setText("" + count);
        } else {
            mHolder.tv_unRead.setVisibility(View.GONE);
        }
        return convertView;
    }


    public class MsgViewHolder {
        public ImageView iv_msgImg;
        public TextView tv_unRead;
        public TextView tv_text;
    }
}